from django.shortcuts import render

# Create your views here.

from dbadmin import  models
def sysconfig(request):
    info = {}
    my_name = request.session.get('username')
    info["my_name"] = my_name

    if request.method == "GET":
        pass
    else:
        ssh_user = request.POST.get("ssh_user")
        ssh_pwd = request.POST.get("ssh_pwd")
        ssh_port = request.POST.get("ssh_port")
        ssh_key = request.POST.get("ssh_key")
        user_status = models.sysconfig.objects.values().count()
        if user_status == 1:
            models.sysconfig.objects.filter(id__gte=0).delete()
            models.sysconfig.objects.create(ssh_user=ssh_user, ssh_pwd=ssh_pwd, ssh_port=ssh_port, ssh_key=ssh_key)
        else:
            models.sysconfig.objects.create(ssh_user=ssh_user,ssh_pwd=ssh_pwd,ssh_port=ssh_port,ssh_key=ssh_key)


    return render(request,"sys_setting.html",info)